package util.parser.wikiXML;

import java.io.File;
import java.io.IOException;
import java.util.Arrays;

import nu.xom.Builder;
import nu.xom.ParsingException;

/**
 * 
 * @author Sergio
 * 
 */

public class XOMDirChecker {

	private static void check(File file, Builder parser) {
		if (file.isDirectory()) { // if a directory
			String[] files = file.list(); // list its files
			Arrays.sort(files); // sort the files
			for (int i = 0; i < files.length; i++)
				// recursively index them
				check(new File(file, files[i]), parser);

		} else if (file.getPath().endsWith(".xml")) { // index .txt files
			try {
				parser.build(file);
			//	System.out.println(file.getPath() + " is well-formed.");
			} catch (ParsingException ex) {
				System.out.println(file.getPath() + " is not well-formed.");
				System.out.println(ex.getMessage());
				System.out.println(" at line " + ex.getLineNumber()
						+ ", column " + ex.getColumnNumber());
			} catch (IOException ex) {
				System.out
						.println("Due to an IOException, the parser could not check "
								+ file.getPath());
			}

		}
	}

	public static void main1(String[] args) {

		if (args.length <= 0) {
			System.out.println("Usage: java nu.xom.samples.XOMChecker URL");
			return;
		}

		Builder parser = new Builder();
		File file = new File(args[0]);

		check(file, parser);

	}
	
	
	
	public static void main(String[] args) {

		String file_ = "F:\\data\\gikip\\EN\\en";
		Builder parser = new Builder();
		File file = new File(file_);

		check(file, parser);

	}

}